package com.wanmait.movie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.wanmait.movie.entity.*;
import com.wanmait.movie.entity.VO.OrderDetailsDTO;
import com.wanmait.movie.mapper.OrderDetailsMapper;
import com.wanmait.movie.service.OrderDetailsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, OrderDetails> implements OrderDetailsService {
    @Resource
    private OrderDetailsMapper orderDetailsMapper;

    @Override
    public List<OrderDetailsDTO> orderDetailsList(String orderNumber) {
        MPJLambdaWrapper<OrderDetails> lambdaWrapper = new MPJLambdaWrapper<>();
        lambdaWrapper.select(OrderDetails::getMoney)
                .select(Screening::getStartTime)
                .select(Movie::getMovieName)
                .select(Cinema::getCinemaName)
                .select(Seat::getSeatNumber)
                .leftJoin(Orders.class, Orders::getOrderNumber, OrderDetails::getOrderId)
                .leftJoin(Seat.class, Seat::getId, OrderDetails::getSeatId)
                .leftJoin(Screening.class, Screening::getId, Orders::getScreeningId)
                .leftJoin(Movie.class, Movie::getId, Screening::getMovieId)
                .leftJoin(Lobby.class, Lobby::getId, Screening::getLobbyId)
                .leftJoin(Cinema.class, Cinema::getId, Lobby::getCinemaId)
                .eq(OrderDetails::getOrderId, orderNumber);
        return orderDetailsMapper.selectJoinList(OrderDetailsDTO.class, lambdaWrapper);
    }
}
